package com.viking.util.database.entry;

import java.sql.*;

public class EntertPatientInformation {
    private static ResultSet resultSet;
    private static int Max;

    public static int getMax() throws Exception {
        Class.forName ("com.mysql.cj.jdbc.Driver");
//        2.用户信息和url
        String url = "jdbc:mysql://8.130.32.3:3306/testing?useUnicode=true&characterEncoding=utf-8";
        String username="testing";
        String password="Yiee4M4sHAaNXAMf";
//        3.连接成功，数据库对象 Connection
        Connection connection = DriverManager.getConnection(url,username,password);
//        4.执行SQL对象Statement，执行SQL的对象

        Statement stmt = connection.createStatement(
                ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
        resultSet= stmt.executeQuery("SELECT COUNT('*') FROM enterinformation");
        while(resultSet.next())
        {
            Max=resultSet.getInt(1);
        }
        resultSet.close();
        connection.close();
        return Max;

    }
    public static String[][] EntertPatientInformation(int start,int limit) throws Exception
    {
        Class.forName ("com.mysql.cj.jdbc.Driver");
//        2.用户信息和url
        String url = "jdbc:mysql://8.130.32.3:3306/testing?useUnicode=true&characterEncoding=utf-8";
        String username="testing";
        String password="Yiee4M4sHAaNXAMf";
//        3.连接成功，数据库对象 Connection
        Connection connection = DriverManager.getConnection(url,username,password);
//        4.执行SQL对象Statement，执行SQL的对象

        Statement stmt = connection.createStatement(
                ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
        resultSet= stmt.executeQuery("SELECT\n" +
                "\tenterinformation.*\n" +
                "FROM\n" +
                "\tenterinformation\n" +
                "LIMIT "+start+","+limit);
        String[][] Data=new String[limit][10];
        int i=0;
        while(resultSet.next())
        {
            Data[i][0] = resultSet.getString(1);
            Data[i][1] = resultSet.getString(2);
            Data[i][2] = resultSet.getString(3);
            Data[i][3] = resultSet.getString(4);
            Data[i][4] = resultSet.getString(5);
            Data[i][5] = resultSet.getString(6);
            Data[i][6] = resultSet.getString(7);
            Data[i][7] = resultSet.getString(8);
            Data[i][8] = resultSet.getString(9);
            Data[i][9] = resultSet.getString(10);
            i++;
        }
        for(i=0;i<limit;i++){
            System.out.print( Data[i][0]+"        ");
            System.out.print( Data[i][1]+"        ");
            System.out.print( Data[i][2]+"        ");
            System.out.print( Data[i][3]+"        ");
            System.out.print( Data[i][4]+"        ");
            System.out.print( Data[i][5]+"        ");
            System.out.print( Data[i][6]+"        ");
            System.out.print( Data[i][7]+"        ");
            System.out.print( Data[i][8]+"        ");
            System.out.print( Data[i][9]+"        ");
            System.out.println("");
        }
        return Data;
    }


    public static void EnterInfo(String name,String sex,int age,String time,String number,String category,String GenderNo,String CaseNo,String id,String BriefMedicalHistory) throws  Exception{
        Class.forName ("com.mysql.cj.jdbc.Driver");
//        2.用户信息和url
        String url = "jdbc:mysql://8.130.32.3:3306/testing?useUnicode=true&characterEncoding=utf-8";
        String username="testing";
        String password="Yiee4M4sHAaNXAMf";
//        3.连接成功，数据库对象 Connection
        Connection connection = DriverManager.getConnection(url,username,password);
        String sql = "insert into enterinformation (姓名,性别,年龄,生日,电话,科别,住院号,病历号,身份证,简要病史) values(?,?,?,?,?,?,?,?,?,?)";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setString(1,name);
        ps.setString(2,sex);
        ps.setInt(3,age);
        ps.setString(4,time);
        ps.setString(5,number);
        ps.setString(6,category);
        ps.setString(7,GenderNo);
        ps.setString(8,CaseNo);
        ps.setString(9,id);
        ps.setString(10,BriefMedicalHistory);
        ps.executeUpdate();
        // 关闭数据库连接对象
        connection.close();




    }
}
